package phone.qyg.com.qyg.adapter;

import android.content.Context;
import android.view.View;

import com.app.adapter.recycler.MultiItemTypeAdapter;
import com.app.adapter.recycler.base.ItemViewDelegate;
import com.app.adapter.recycler.base.ViewHolder;

import java.util.List;

import phone.qyg.com.qyg.R;
import phone.qyg.com.qyg.model.baidu.LineInfo;

/**
 * 作者：lblbh on 2017/6/30 16:39
 * 邮箱：lanbuhan@163.com
 * 功能：TODO
 */
public class FitnessLineAdapter extends MultiItemTypeAdapter<LineInfo> {

    OnLocalHostMap onLocalHostMap;
    public FitnessLineAdapter(Context context, List<LineInfo> datas, OnLocalHostMap onLocalHostMap) {
        super(context, datas);
        this.onLocalHostMap = onLocalHostMap;
        addItemViewDelegate(new FitnessLineOne());
        addItemViewDelegate(new FitnessLineTwo());
    }


    public class FitnessLineOne implements ItemViewDelegate<LineInfo> {

        @Override
        public int getItemViewLayoutId() {
            return R.layout.item_line_detail;
        }

        @Override
        public boolean isForViewType(LineInfo item, int position) {
            return (item.localType == 0);
        }

        @Override
        public void convert(ViewHolder holder, LineInfo model, int position) {
            int time = model.duration;
            int distance = model.distance;

            //时间设置
            if ( time / 3600 == 0 ) {
                holder.setText(R.id.user_name,time / 60 + "分钟");
            } else {
                holder.setText(R.id.user_name,time / 3600 + "小时" + (time % 3600) / 60 + "分钟" );
            }

            //设置距离
            holder.setText(R.id.item_distance,(float)(Math.round(distance*10))/10000+"公里");

            int type = model.type;

            if(type == 1){
                //1-驾车
                holder.setVisible(R.id.transit_linear,false);

                holder.setText(R.id.line_name,model.title);
                //(CommonUtil.isRequestList(model.lineDetail)?model.lineDetail.get(0):"驾车行驶")
            }else{
                //0-公交
                int walk = model.walk;
                holder.setText(R.id.line_name,model.line_name);
                holder.setVisible(R.id.transit_linear,(walk > 0)?true:false);
                holder.setText(R.id.item_walk,"步行"+walk+"米");
            }
        }
    }

    public class FitnessLineTwo implements ItemViewDelegate<LineInfo> {

        @Override
        public int getItemViewLayoutId() {
            return R.layout.line_local_map;
        }

        @Override
        public boolean isForViewType(LineInfo item, int position) {
            return (item.localType != 0);
        }

        @Override
        public void convert(ViewHolder holder, LineInfo test, int position) {
            holder.setOnClickListener(R.id.local_host, new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(onLocalHostMap != null)
                        onLocalHostMap.onClickLocal();
                }
            });
        }
    }

    public interface OnLocalHostMap{
        public void onClickLocal();
    }
}
